# 导入数据请求模块，第三方模块 需要在cmd里面 pip install requests
import json

import requests
import urllib.parse

"""
1. 发送请求，对于模拟浏览器对于URL地址发送请求
    - 如何批量替换内容
        (.*?):(.*)
        '$1':'$2',
"""

# 确定请求URL地址
url = "https://i.waimai.meituan.com/tsp/open/openh5/home/shopList"
# 请求参数，字段数据类型，构建完整键值对
data = {
    'set_name': ' waimai-west',
    'region_id': ' 1000500100',
    '_': ' 1723445019938',
    'yodaReady': ' h5',
    'csecplatform': ' 4',
    'csecversion': ' 3.0.0',
}
# 表单参数，构建完整的键值对
formData = {
    'optimus_code': ' 10',
    'optimus_risk_level': ' 71',
    'pageSize': ' 20',
    'page_index': ' 1',
    'offset': ' 20',
    'content_personalized_switch': ' 0',
    'sort_type': ' ',
    'slider_select_data': ' ',
    'activity_filter_codes': ' ',
    'wm_latitude': ' 29623463',
    'wm_longitude': ' 106474454',
    'wmUuidDeregistration': ' 0',
    'wmUserIdDeregistration': ' 0',
    'openh5_uuid': ' 4D6156BE75B1E714EF9984FFCD53A07E1879862AC17B0AA7117113807AFAD1E4',
    'uuid': ' 4D6156BE75B1E714EF9984FFCD53A07E1879862AC17B0AA7117113807AFAD1E4',
}
# 请求头: 伪装，把python代码伪装（模拟）成浏览器发送请求
headers = {
    'accept': 'application/json',
    'sec-ch-ua-platform':"Android",
    # referer 防盗链，告诉服务器我们请求URL地址从哪里跳转过来的
    'referer': 'https://h5.waimai.meituan.com/',
    # user-agent 用户代理，表示浏览器基本身份标识
    'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) '
                  'Chrome/127.0.0.0 Mobile Safari/537.36',
    'cookie': '_ga=GA1.2.1711544168.1723018230; _ga_LYVVHCWVNG=GS1.1.1723018230.1.0.1723018236.0.0.0; '
              '_ga_FSX5S86483=GS1.1.1723018230.1.0.1723018236.0.0.0; '
              '_lxsdk_cuid=1912be3d27ac8-0f55123eff0fb9-26001e51-1fa400-1912be3d27ac8; '
              'uuid=e074684b45264fccb98f.1723018272.1.0.0; mtcdn=K; '
              'userTicket=khDgzqTKFxnAiKFSGhaArcrYVBZhaTYnlfdMFYsQ; u=31612252; n=cqzhongxc; '
              'm=cqzhongxc%40hotmail.com; '
              'lt=AgFFJvnQ7D_SWnJPr33fLmR8D5sigMnMdFpNwuWHOmVbU9R70xZhglx7_tj78K6ZNvfCuvsqrXktkQAAAAARIgAAq8DNF0Td3SqdoiPGxhvb8dmj0401SQa3AShKo4jkjmfLtuK-isDJD22mZV4aqiLE; token2=AgFFJvnQ7D_SWnJPr33fLmR8D5sigMnMdFpNwuWHOmVbU9R70xZhglx7_tj78K6ZNvfCuvsqrXktkQAAAAARIgAAq8DNF0Td3SqdoiPGxhvb8dmj0401SQa3AShKo4jkjmfLtuK-isDJD22mZV4aqiLE; wm_order_channel=default; swim_line=default; utm_source=; au_trace_key_net=default; WEBDFPID=v55x037052655w63z9uxu7109xz31wu78087yv302419795848v44xw4-2038378416141-1723018415751IISESEWfd79fef3d01d5e9aadc18ccd4d0c95078572; isIframe=false; terminal=i; w_utmz="utm_campaign=(direct)&utm_source=5000&utm_medium=(none)&utm_content=(none)&utm_term=(none)"; _lx_utm=utm_source%3Dbing%26utm_medium%3Dorganic; w_visitid=362259e7-a468-4165-b2d2-29aefbeda22f; iuuid=4D6156BE75B1E714EF9984FFCD53A07E1879862AC17B0AA7117113807AFAD1E4; token=AgGuIeGh3a7mVySET69CUrBhotk0tgziEJ472_ew2LN6tgBEE8xPIlyGRXzdnFKIHI6JjQF-kIs8jQAAAAAnIgAAODq66mnJ9wB-GMx5mPqVPibnDWJn_C4uwOKRR-cj1lrzskIyo3Ywx6ph-hYkovtn; mt_c_token=AgGuIeGh3a7mVySET69CUrBhotk0tgziEJ472_ew2LN6tgBEE8xPIlyGRXzdnFKIHI6JjQF-kIs8jQAAAAAnIgAAODq66mnJ9wB-GMx5mPqVPibnDWJn_C4uwOKRR-cj1lrzskIyo3Ywx6ph-hYkovtn; oops=AgGuIeGh3a7mVySET69CUrBhotk0tgziEJ472_ew2LN6tgBEE8xPIlyGRXzdnFKIHI6JjQF-kIs8jQAAAAAnIgAAODq66mnJ9wB-GMx5mPqVPibnDWJn_C4uwOKRR-cj1lrzskIyo3Ywx6ph-hYkovtn; userId=31612252; _lxsdk=4D6156BE75B1E714EF9984FFCD53A07E1879862AC17B0AA7117113807AFAD1E4; openh5_uuid=4D6156BE75B1E714EF9984FFCD53A07E1879862AC17B0AA7117113807AFAD1E4; w_token=AgGuIeGh3a7mVySET69CUrBhotk0tgziEJ472_ew2LN6tgBEE8xPIlyGRXzdnFKIHI6JjQF-kIs8jQAAAAAnIgAAODq66mnJ9wB-GMx5mPqVPibnDWJn_C4uwOKRR-cj1lrzskIyo3Ywx6ph-hYkovtn; openh5_uuid=4D6156BE75B1E714EF9984FFCD53A07E1879862AC17B0AA7117113807AFAD1E4; _lxsdk_s=191455031d3-7ca-da6-ff3%7C%7C101',
    'mtgsig': '{"a1":"1.2","a2":1723445019939,"a3":"v55x037052655w63z9uxu7109xz31wu78087yv302419795848v44xw4","a5":"RcW6WehmN78nURqqovd5PeulTWgc5lYEUPi9rrq/GoqqfTu7P6TaFXlNIHnXTeU9A8i=","a6":"h1.71CVOIQePFdz+NBfmTpqs8vlMRzCsmXyMPz7zcVX6lxCNLHyiU0UlI5zBqvla4bGpJHau3J65m+/gHOWOEbEMvW5DNjzGxjpqZbv70VnAmvyRherJFUIrHlHsy7hpqqXW8vqlvqTuVNzm2BS0D8tyAWpo6MFS3/XOSVD/4f9+a30WEelQ8YrwrsRLFn2lmeoFJizynLVGUM/PhGYOMRoJFejct8qW6o+a7BuweBeQ9JtkANaaNLiNF3x7WNhOl2aHEYCyQCTL6hnIbn1FFvcu0iwotHtSUmh0pxGWlBzMLD8HzwTG+3R5F5zMkX7zNJs2FjVVpd8KzzVQT0G8fQ9z/s0v/0bDcaBfXEZKlXN+/6AOYx0zP8N2qVCx+/0mhRqpY07js4sMuju8NrLKgsdAs7brcFZNPGppiY7SkMugh6G3oTmswJUsKmbEfJAeQDNV","a8":"43726b4df478126c76f40a5288eed2fb","a9":"3.0.0,7,39","a10":"d0","x0":4,"d1":"ed7100dc07350c05bd9f4809ea440cc1"}'
}
# 发送请求 <Response [403]> 返回响应对象 403状态码 表示请求你没有访问权限《没有请求成功》
# response = requests.get(url=url, headers=headers, params=data)
response = requests.post(url=url + urllib.parse.urlencode(data), data=formData, headers=headers)
print(response)

